package com.android.scanner.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.scanner.R;
import com.android.scanner.bean.Bob;
import com.android.scanner.utils.Constant;

public class BBListAdapter extends ListBaseAdapter {

	private List<Bob> list = new ArrayList<Bob>();
	private Context mContext;

	public BBListAdapter(Context ctx) {
		this.mContext = ctx;
		list.clear();
		list.add(new Bob("1", "a001", "2014/1/1"));
		list.add(new Bob("2", "b", "2014/1/2"));
		list.add(new Bob("3", "c", "2014/1/3"));
		list.add(new Bob("4", "d", "2014/1/4"));
		list.add(new Bob("5", "e", "2014/1/5"));
		list.add(new Bob("6", "f", "2014/1/6"));
		list.add(new Bob("7", "g", "2014/1/7"));
		list.add(new Bob("8", "h", "2014/1/8"));
		list.add(new Bob("9", "i", "2014/1/9"));
		list.add(new Bob("10", "j", "2014/1/10"));
		list.add(new Bob("11", "k", "2014/1/11"));
		list.add(new Bob("12", "l", "2014/1/12"));
		list.add(new Bob("13", "m", "2014/1/13"));
		list.add(new Bob("14", "n", "2014/1/14"));
		list.add(new Bob("15", "o", "2014/1/15"));
	}

	public BBListAdapter(Context ctx, List<Bob> list) {
		this.mContext = ctx;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		// TODO Auto-generated method stub
		Holder holder;
		if (view == null) {
			holder = new Holder();
			view = LayoutInflater.from(mContext).inflate(R.layout.bb_list_item, null);
			holder.item_id = (TextView) view.findViewById(R.id.item_id);
			holder.bb_code = (TextView) view.findViewById(R.id.bb_code);
			holder.bb_hole_num = (TextView) view.findViewById(R.id.bb_hole_num);
			holder.delay = (TextView) view.findViewById(R.id.delay);
			view.setTag(holder);
		} else {
			holder = (Holder) view.getTag();
		}

		holder.item_id.setText(String.valueOf(position + 1));
		holder.bb_code.setText(list.get(position).getCode());
		holder.bb_hole_num.setText(list.get(position).getHoleNum());
		holder.delay.setText(list.get(position).getDelayStr());
		if (position == hlPosition) {
			holder.item_id.setTextSize(Constant.LIST_TEXT_HL_SIZE);
			holder.bb_code.setTextSize(Constant.LIST_TEXT_HL_SIZE);
			holder.bb_hole_num.setTextSize(Constant.LIST_TEXT_HL_SIZE);
			holder.delay.setTextSize(Constant.LIST_TEXT_HL_SIZE);
		} else {
			holder.item_id.setTextSize(Constant.LIST_TEXT_SIZE);
			holder.bb_code.setTextSize(Constant.LIST_TEXT_SIZE);
			holder.bb_hole_num.setTextSize(Constant.LIST_TEXT_SIZE);
			holder.delay.setTextSize(Constant.LIST_TEXT_SIZE);
		}

		return view;
	}

	class Holder {
		TextView item_id;
		TextView bb_code;
		TextView bb_hole_num;
		TextView delay;
	}
}
